import requests
from bs4 import BeautifulSoup
from madeInChina import analyze

# 所有一级分类和二级分类
def findcatlist(url):
    res = requests.get(url)
    html = res.text
    # 解析
    soup = BeautifulSoup(html, 'html.parser')
    catcontent = soup.select('.catlog-hot')[0]
    # 一级分类名称
    first = catcontent.select('h1')[0].text
    print('分类: '+first)
    # 二级分类
    second = catcontent.select('.cate-item-wrap')
    for item in second:
        # 二级分类名
        secondName = item.select('.sub-cat-title')[0].text
        print('         '+secondName)
        # 三级分类list
        third = item.select('.sub-cat-child')
        for thirdItem in third:
            atag = thirdItem.select('a')
            for aitem in atag:
                # 三级分类名
                thirdName = aitem.get('title')
                # 三级分类地址
                thirdHref = 'https:' + aitem.get('href')
                total = analyze.analyze(thirdHref)
                print('             商品: ' + thirdName + '\t在售总数: ' + total)
